﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vit.Database;
using Vit.Common.Extensions;
using Vit.Database.DataAccess;

namespace Vit.Database.Schema
{
    public class ParameterSchemaInfoRowMapper : IRowMapper<ParameterSchemaInfo>
    {
        #region IRowMapper<ColumnSchemaInfo> Members

        public ParameterSchemaInfo MapRow(IDataRecord row)
        {
            ParameterSchemaInfo obj = new ParameterSchemaInfo();
            obj.SchemaName = row["SchemaName"].ConvertTo<string>(string.Empty);
            obj.OwnerName = row["OwnerName"].ConvertTo<string>(string.Empty);
            obj.ObjectType = row["ObjectType"].ConvertTo<CommandObjectType>(CommandObjectType.StoredProcedure);
            obj.ObjectName = row["ObjectName"].ConvertTo<string>(string.Empty);
            obj.ParameterName = row["ParameterName"].ConvertTo<string>(string.Empty);
            obj.ParameterOrder = row["ParameterOrder"].ConvertTo<int>(0);
            obj.NativeType = row["NativeType"].ConvertTo<string>(string.Empty);
            obj.Size = row["Size"].ConvertTo<int?>(null);
            obj.Scale = row["Scale"].ConvertTo<int?>(null);
            obj.Precision = row["Precision"].ConvertTo<byte?>(null);
            obj.Direction = row["Direction"].ConvertTo<ParameterDirection>(ParameterDirection.Input);
            obj.IsResult = row["IsResult"].ConvertTo<bool>(false);

            return obj;
        }

        #endregion
    }
}
